<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="description" content="A fully featured admin theme which can be used to build CRM, CMS, etc.">
    <meta name="author" content="Coderthemes">
	
	<!-- jQuery  -->
    <script type="text/javascript" src="/static/plugins/jquery/jquery-3.6.0.min.js"></script>
	
	<!-- layui  -->
	<link rel="stylesheet" href="/static/plugins/layui/2.7.6/css/layui.css" media="all" />
	<script src="/static/plugins/layui/2.7.6/layui.js" charset="utf-8"></script>
	
	<!-- form style -->
	<link rel="stylesheet" href="/static/admin/css/mini-ease-edit.css">
	<!-- form js -->
	<script src="/static/admin/js/YsForm.js" charset="utf-8"></script>
	
	<!-- iconfont -->
	<link rel="stylesheet" href="/static/css/icon/iconfont.css" media="all" />
	
	<!-- 基于laiui的表格 -->
	<script type="text/javascript" src="/static/js/business/tbBaseinfoSpcz/simple_table_TP_BaseinfoSpcz_for_edit.js"></script>
</head>

<body>

<div class="layui-layout layui-layout-admin">
	<form class="layui-form" id="formId" method="post" th:action="${dto.pathCommit}">
		
		<!-- include 顶部按钮 -->
		<th:block th:include="include/flow :: buttonHTML"/>
		<th:block th:include="include/flow :: buttonJS"/>
		
		<div class="layui-body">
			<!-- include 表单，由JS渲染，表单ID默认为：id_form， -->
			<div id="id_form">
			</div>
			<script th:inline="javascript">
			// 表单初始化
			var formOfAdd = null;
			//使用layui的sku模块
			layui.use(['form', 'YsForm', 'jquery'], function(){
				var $ = layui.jquery,YsForm = layui.YsForm,form = layui.form;
				formOfAdd = YsForm.init({ id:'id_form', cols: $.parseJSON(JSON.stringify([[${dto.rows}]])) });
			});
			</script>
	
			<!-- 商品子表 -->
			<div class="layui-form-item">
				<div id="simple_table_TP_BaseinfoSpcz_for_edit">
				</div>
				<script th:inline="javascript">
				var tableOfChild = null;
				//使用layui的sku模块
				layui.use(['form', 'simple_table_TP_BaseinfoSpcz_for_edit', 'jquery'], function(){
					var $ = layui.jquery,simple_table_TP_BaseinfoSpcz_for_edit = layui.simple_table_TP_BaseinfoSpcz_for_edit,form = layui.form;
	            	
					tableOfChild = simple_table_TP_BaseinfoSpcz_for_edit.init({ id:'simple_table_TP_BaseinfoSpcz_for_edit', data: $.parseJSON(JSON.stringify([[${sonlist}]])), pcode: [[${pcode}]]});
				});
				</script>
			</div>
		</div>
		
		<div class="layui-footer">
			<th:block th:include="include/form :: footerHTML"/>
		</div>
	</form>
</div>
	<script>
	$(function () {
		layui.use(['form'], function(){
			var form = layui.form;
			
			// 表单提交，共用同一个
			form.on('submit(formSubmit)', function(data){
				var indexOfLoading = layer.load(1, {
					shade: [0.5,'#000000'] //0.1透明度的白色背景
				});
				
				data.field['sonlist'] = JSON.stringify(tableOfChild.getData());
				$.post(data.form.action, data.field, function(res){
					if (res.code == 0) {
						layer.msg('操作成功');
						var dto = res.data;
						setTimeout(function(){
							if(dto == null || dto == undefined) {
								return;
							} else if(dto.code == 0) {
								layer.close(indexOfLoading);
								return;
							} else if(dto.code == 2) {
								// 关闭并刷新父列表
								window.parent.layer.close(parent.layer.getFrameIndex(window.name));
								window.parent.reloadTableOfList();
							} else if(dto.code == 3) {
								// 刷新当前页面
								window.location.href = dto.url;
							}
						}, 2000);
					} else {
						layer.close(indexOfLoading);
						layer.msg(res.msg);
					}
				});
				return false;
			});
		});
	});
	</script>
</body>
</html>